package org.example.flux;


import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import reactor.core.publisher.Flux;

/**
 * 日志controller
 *
 * @author 欧阳劲驰
 * @since 0.0.1
 */
@Controller
@RequestMapping("log")
@Slf4j
public class LogControl {

    final LogManager logManager;

    public LogControl(LogManager logManager) {
        this.logManager = logManager;
    }

    /**
     * @return 日志页
     */
    @GetMapping("")
    public String index() {
        return "log";
    }


    /**
     * 获取日志
     *
     * @return 日志流
     */
    @GetMapping(value = "getLog", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    @ResponseBody
    public Flux<String> getLog() {
        return logManager.getLog();
    }
}
